package com.sa.token.controller;

import cn.dev33.satoken.stp.StpUtil;
import com.sa.token.dto.request.role.SetRoleRequest;
import com.sa.token.dto.request.user.UpdatePwdRequest;
import com.sa.token.dto.request.user.UserInfoRequest;
import com.sa.token.message.StandardResponse;
import com.sa.token.service.SysUserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @desc： 用户信息
 * @author： xhs
 * @date： 2021/8/27 16:23
 * @version： JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/api/userInfo")
public class UserInfoController {
    @Autowired
    private SysUserInfoService userInfoService;

    /**
     * 完善用户信息
     *
     * @param userInfoRequest
     * @return
     */
    @PostMapping("/insertUserInfo")
    public StandardResponse insertUserInfo(@Valid @RequestBody UserInfoRequest userInfoRequest) {
        StandardResponse response = userInfoService.insertUserInfo(userInfoRequest);
        return response;
    }

    /**
     * 获取用户信息
     *
     * @return
     */
    @GetMapping("/getUserInfo")
    public StandardResponse getUserInfo() {
        StandardResponse response = userInfoService.getUserInfo();
        return response;
    }

    /**
     * 修改密码
     *
     * @param updatePwdRequest
     * @return
     */
    @PostMapping("/updatePwd")
    public StandardResponse updatePwd(@Valid @RequestBody UpdatePwdRequest updatePwdRequest) {
        StandardResponse response = userInfoService.updatePwd(updatePwdRequest);
        return response;
    }

    /**
     * 编辑用户信息
     *
     * @param userInfoRequest
     * @return
     */
    @PostMapping("/updateUserInfo")
    public StandardResponse updateUserInfo(@Valid @RequestBody UserInfoRequest userInfoRequest) {
        StandardResponse response = userInfoService.updateUserInfo(userInfoRequest);
        return response;
    }

    /**
     * 设置角色
     *
     * @param setRoleRequest
     * @return
     */
    @PostMapping("/setRole")
    public StandardResponse setRole(@Valid @RequestBody SetRoleRequest setRoleRequest) {
        log.info("-----------------【设置角色接口setRole()入参 setRoleRequest：{}】--------------", setRoleRequest.toString());
        StandardResponse response = userInfoService.setRole(setRoleRequest);
        return response;
    }
}
